﻿Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Public Class frmPurchaseHistory

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        'loadReport()
        ' Add any initialization after the InitializeComponent() call.

    End Sub
    'Private Sub loadReport()
    '    Dim path = "D:\CrystalReport\testGroup.rpt" 'Application.StartupPath & "\CrystalReport\PoliceReportAll.rpt"
    '    Dim app As New CRAXDDRT.Application()
    '    Dim doc = app.OpenReport(path)
    '    'doc.ParameterFields.GetItemByName("EmpId").AddCurrentValue(id)
    '    rptViewer.ReportSource = doc
    '    rptViewer.ViewReport()
    '    rptViewer.Refresh()
    'End Sub

    Private Sub frmPurchaseHistory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
    End Sub
    Private Sub loadReportPara()
        Dim cryRpt As New ReportDocument
        Dim param = New ParameterField
        Dim startDate = New ParameterField
        Dim endDate = New ParameterField
        Dim myDiscreteValue = New ParameterDiscreteValue
        startDate.ParameterFieldName() = "startDate"
        myDiscreteValue.Value = dtpstart.Value
        startDate.CurrentValues.Add(myDiscreteValue)
        endDate.ParameterFieldName() = "endDate"
        myDiscreteValue.Value = dtpend.Value
        endDate.CurrentValues.Add(myDiscreteValue)
        'param.Add()
        cryRpt.Load(Application.StartupPath + "\CrystalReport\PurchaseDetail.rpt")
        cryRpt.ParameterFields.Add(startDate)
        cryRpt.ParameterFields.Add(endDate)
        'param.Add(startDate)
        crviewerr.ReportSource = cryRpt
        'crviewerr.ParameterFieldInfo = param
        crviewerr.Refresh()
    End Sub
    Private Sub LoadRptPara()
        Dim crRDoc As ReportDocument
        Dim crParaFiDes As ParameterFieldDefinitions
        Dim crParaFiDe As ParameterFieldDefinition
        Dim crParaValue As ParameterValue
        Dim crParaDiscVa As ParameterDiscreteValue
        Dim rptPath = Application.StartupPath + "\CrystalReport\PurchaseDetail.rpt"

        crRDoc = New ReportDocument
        crRDoc.Load(rptPath)

        crParaFiDes = crRDoc.DataDefinition.ParameterFields

        crParaFiDe = crParaFiDes.Item("startDate")
        'crParaValue = crParaFiDe.CurrentValues
        crParaDiscVa = New CrystalDecisions.Shared.ParameterDiscreteValue
        crParaDiscVa.Value = dtpstart.Value
        'crParaValue.Add(crParaDiscVa)
        crParaFiDe.ApplyCurrentValues(crParaValue)
        crviewerr.ReportSource = crRDoc


    End Sub

    Private Sub loadRpt()
        Dim cryRpt As New ReportDocument
        Dim path As String = IIf(radioSumm.Checked, "\CrystalReport\Purchase.rpt", "\CrystalReport\PurchaseDetail.rpt")

        cryRpt.Load(Application.StartupPath + path)
        cryRpt.SetParameterValue("startDate", dtpstart.Value)
        cryRpt.SetParameterValue("endDate", dtpend.Value)
        crviewerr.ReportSource = cryRpt
        crviewerr.Refresh()
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        loadRpt()
        'loadReportPara()
    End Sub

    Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click
        crviewerr.PrintReport()
    End Sub
End Class